﻿namespace SafetyRecordData.Data.DAL
{
    using System;
    using System.Data;
    using System.Data.Common;
    using System.IO;
    using System.Web;
    using Ths.Components.Common;
    using Ths.Components.Excel;
    using Wuqi.Webdiyer;

    [Serializable]
    public class DASanWeiMessage : DBBase
    {
        private const string SanWeiMessage_DefaultList_DCOUNT = "select count(*)  FROM SanWeiMessage {0}";
        private const string SanWeiMessage_DefaultList_DSQL = "\r\n\t\tSELECT * FROM (\r\n\t\t    SELECT row_number() OVER({0}) as ROW_NUMBER,* FROM \r\n\t\t    ( \r\n\t\t        SELECT  [AppID] AS [AppID],  [Company] AS [Company],  [workerNumber] AS [workerNumber],  [Name] AS [Name],  [Sex] AS [Sex],  [Birthsday] AS [Birthsday],  [Card] AS [Card],  [Type] AS [Type]  FROM [SanWeiMessage]\r\n\t\t        {1}\r\n\t\t    ) as a\r\n\t\t) as b WHERE ROW_NUMBER > {2} AND ROW_NUMBER <= {3}";

        public DASanWeiMessage()
        {
            base.TableName = "SanWeiMessage";
            base.PKField = "AppID";
        }

        public DASanWeiMessage(string connectionStringName) : base(connectionStringName)
        {
            base.TableName = "SanWeiMessage";
            base.PKField = "AppID";
        }

        public DataTable GetHurtListCount(DbParameter[] parameters, string orderBy, string where)
        {
            DataTable dt = base.DBFactory.GetDataTable("proc_SanWeiMessage", CommandType.StoredProcedure, parameters);
            ExcelEntity _excel = new ExcelEntity();
            _excel.Sql = string.Format(" exec proc_SanWeiMessageExcel " + where, new object[] { orderBy, where, 0, 100 });
            _excel.Parameters = parameters;
            HttpContext.Current.Session[Path.GetFileName(HttpContext.Current.Request["Url"].ToString())] = _excel;
            return dt;
        }

        public DataTable GetHurtListDetailCount(DbParameter[] parameters, string orderBy, string where)
        {
            DataTable dt = base.DBFactory.GetDataTable("proc_SanWeiMessageDetail", CommandType.StoredProcedure, parameters);
            ExcelEntity _excel = new ExcelEntity();
            _excel.Sql = string.Format(" exec proc_SanWeiMessageDetailExcel " + where, new object[] { orderBy, where, 0, 100 });
            _excel.Parameters = parameters;
            HttpContext.Current.Session[Path.GetFileName(HttpContext.Current.Request["Url"].ToString())] = _excel;
            return dt;
        }

        public DataTable SanWeiMessage_DefaultListPR(AspNetPager AspNetPager1, DbParameter[] parameters, string orderBy, string where)
        {
            string sql = string.Format("select count(*)  FROM SanWeiMessage {0}", where);
            CommonClass.InitAspPageInfo(CommonUtility.Get_Int32(base.DBFactory.ExecuteScalar(sql, CommandType.Text, parameters)), AspNetPager1);
            sql = string.Format("\r\n\t\tSELECT * FROM (\r\n\t\t    SELECT row_number() OVER({0}) as ROW_NUMBER,* FROM \r\n\t\t    ( \r\n\t\t        SELECT  [AppID] AS [AppID],  [Company] AS [Company],  [workerNumber] AS [workerNumber],  [Name] AS [Name],  [Sex] AS [Sex],  [Birthsday] AS [Birthsday],  [Card] AS [Card],  [Type] AS [Type]  FROM [SanWeiMessage]\r\n\t\t        {1}\r\n\t\t    ) as a\r\n\t\t) as b WHERE ROW_NUMBER > {2} AND ROW_NUMBER <= {3}", new object[] { orderBy, where, (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex * AspNetPager1.PageSize });
            ExcelEntity _excel = new ExcelEntity();
            _excel.Sql = string.Format("\r\n\t\tSELECT * FROM (\r\n\t\t    SELECT row_number() OVER({0}) as ROW_NUMBER,* FROM \r\n\t\t    ( \r\n\t\t        SELECT  [AppID] AS [AppID],  [Company] AS [Company],  [workerNumber] AS [workerNumber],  [Name] AS [Name],  [Sex] AS [Sex],  [Birthsday] AS [Birthsday],  [Card] AS [Card],  [Type] AS [Type]  FROM [SanWeiMessage]\r\n\t\t        {1}\r\n\t\t    ) as a\r\n\t\t) as b WHERE ROW_NUMBER > {2} AND ROW_NUMBER <= {3}", new object[] { orderBy, where, 0, AspNetPager1.RecordCount });
            _excel.Parameters = parameters;
            HttpContext.Current.Session[Path.GetFileName(HttpContext.Current.Request["Url"].ToString())] = _excel;
            DataTable dt = base.DBFactory.GetDataTable(sql, CommandType.Text, parameters);
            return base.FullRow(dt, AspNetPager1.PageSize);
        }
    }
}

